package day9;

import java.io.*;
import java.net.Socket;
import java.time.LocalDate;
import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class ObjectSenderThread  extends Thread{
    private final Socket s;
    private Map<String,String> map=new HashMap<>();
    public ObjectSenderThread(Socket s){
        this.s=s;
        map.put("clsName","java75");
        map.put("dirTeacher","老刘");
        map.put("最帅","赵鹏程");
        map.put("Zuigao","赵鹏程");
        map.put("time", LocalDate.now().toString());
    }

    @Override
    public void run() {
        try {
            System.out.println(s+"链接上了");
            OutputStream out = s.getOutputStream();
            InputStream in = s.getInputStream();
            ObjectOutputStream oout=new ObjectOutputStream(out);
            ObjectInputStream oin=new ObjectInputStream(in);
            oout.writeObject(map);
            oout.reset();//!!!!!
            oout.flush();
            List list =(List) oin.readObject();
            System.out.println("从"+s+"收到了："+list);
        } catch (Exception e) {
            System.out.println(e);
        } finally {
            try {
                s.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
